home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH8 / 8-3.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  13.6 KB  |  396 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCheckbook 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Check"
  5.    ClientHeight    =   4020
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1485
  8.    ClientWidth     =   7935
  9.    ControlBox      =   0   'False
  10.    BeginProperty Font 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   8.25
  13.       Charset         =   0
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    LinkTopic       =   "Form1"
  20.    MaxButton       =   0   'False
  21.    MinButton       =   0   'False
  22.    PaletteMode     =   1  'UseZOrder
  23.    ScaleHeight     =   4020
  24.    ScaleWidth      =   7935
  25.    Begin VB.CommandButton cmdPrint 
  26.       Caption         =   "&Print Report"
  27.       Height          =   495
  28.       Left            =   4320
  29.       TabIndex        =   15
  30.       Top             =   3360
  31.       Width           =   1575
  32.    End
  33.    Begin VB.CommandButton cmdQuit 
  34.       Caption         =   "&Quit"
  35.       Height          =   495
  36.       Left            =   6360
  37.       TabIndex        =   16
  38.       Top             =   3360
  39.       Width           =   1455
  40.    End
  41.    Begin VB.CommandButton cmdRecord 
  42.       Caption         =   "&Record This Check"
  43.       Height          =   495
  44.       Left            =   120
  45.       TabIndex        =   13
  46.       Top             =   3360
  47.       Width           =   2055
  48.    End
  49.    Begin VB.CommandButton cmdMode 
  50.       Caption         =   "&Switch  to Deposits"
  51.       Height          =   495
  52.       Left            =   2280
  53.       TabIndex        =   14
  54.       Top             =   3360
  55.       Width           =   1935
  56.    End
  57.    Begin VB.PictureBox picBox 
  58.       Height          =   2655
  59.       Left            =   120
  60.       ScaleHeight     =   2595
  61.       ScaleWidth      =   7635
  62.       TabIndex        =   0
  63.       TabStop         =   0   'False
  64.       Top             =   120
  65.       Width           =   7695
  66.       Begin VB.TextBox txtDate 
  67.          Height          =   285
  68.          Left            =   5760
  69.          TabIndex        =   4
  70.          Top             =   690
  71.          Width           =   1812
  72.       End
  73.       Begin VB.TextBox txtAmount 
  74.          Height          =   285
  75.          Left            =   5760
  76.          TabIndex        =   8
  77.          Top             =   1320
  78.          Width           =   1812
  79.       End
  80.       Begin VB.TextBox txtMemo 
  81.          Height          =   285
  82.          Left            =   840
  83.          TabIndex        =   10
  84.          Top             =   2010
  85.          Width           =   3852
  86.       End
  87.       Begin VB.TextBox txtToFrom 
  88.          Height          =   285
  89.          Left            =   840
  90.          TabIndex        =   6
  91.          Top             =   1290
  92.          Width           =   3852
  93.       End
  94.       Begin VB.TextBox txtNum 
  95.          Alignment       =   1  'Right Justify
  96.          BorderStyle     =   0  'None
  97.          Height          =   225
  98.          Left            =   6960
  99.          TabIndex        =   2
  100.          Top             =   210
  101.          Width           =   495
  102.       End
  103.       Begin VB.Label lblAmount 
  104.          BackStyle       =   0  'Transparent
  105.          Caption         =   "Amount $"
  106.          Height          =   252
  107.          Left            =   4920
  108.          TabIndex        =   7
  109.          Top             =   1320
  110.          Width           =   852
  111.       End
  112.       Begin VB.Label lblDate 
  113.          BackStyle       =   0  'Transparent
  114.          Caption         =   "Date"
  115.          Height          =   252
  116.          Left            =   5280
  117.          TabIndex        =   3
  118.          Top             =   720
  119.          Width           =   372
  120.       End
  121.       Begin VB.Label lblMemo 
  122.          BackStyle       =   0  'Transparent
  123.          Caption         =   "Memo"
  124.          Height          =   255
  125.          Left            =   240
  126.          TabIndex        =   9
  127.          Top             =   2040
  128.          Width           =   495
  129.       End
  130.       Begin VB.Label lblToFrom 
  131.          Alignment       =   1  'Right Justify
  132.          BackStyle       =   0  'Transparent
  133.          Caption         =   "Pay To"
  134.          Height          =   255
  135.          Left            =   120
  136.          TabIndex        =   5
  137.          Top             =   1320
  138.          Width           =   615
  139.       End
  140.       Begin VB.Label lblName 
  141.          BackStyle       =   0  'Transparent
  142.          Height          =   195
  143.          Left            =   360
  144.          TabIndex        =   1
  145.          Top             =   240
  146.          Width           =   3255
  147.       End
  148.    End
  149.    Begin VB.Label lblBalance 
  150.       BackStyle       =   0  'Transparent
  151.       Height          =   255
  152.       Left            =   4320
  153.       TabIndex        =   12
  154.       Top             =   3000
  155.       Width           =   1575
  156.    End
  157.    Begin VB.Label lblcurbal 
  158.       Alignment       =   1  'Right Justify
  159.       Caption         =   "Current Balance"
  160.       Height          =   255
  161.       Left            =   2760
  162.       TabIndex        =   11
  163.       Top             =   3000
  164.       Width           =   1455
  165.    End
  166. Attribute VB_Name = "frmCheckbook"
  167. Attribute VB_GlobalNameSpace = False
  168. Attribute VB_Creatable = False
  169. Attribute VB_PredeclaredId = True
  170. Attribute VB_Exposed = False
  171. Dim fileName As String   'Name of data file
  172. Dim nameOnChk As String  'Name to appear on checks
  173. Dim lastCkNum As Integer 'Number of last check written
  174. Dim lastDpNum As Integer 'Number of last deposit slip processed
  175. Dim curBal As Single     'Current balance in account
  176. Dim transType As String  'Type of transaction, check or deposit
  177. Private Function AllDataGiven() As Boolean
  178.   Dim message As String
  179.   'If one of the four required pieces of information
  180.   'is missing, assign its name to message
  181.   message = ""
  182.   If txtDate.Text = "" Then
  183.       message = "Date"
  184.       txtDate.SetFocus
  185.     ElseIf txtToFrom.Text = "" Then
  186.       If transType = "Check" Then
  187.           message = "Pay To"
  188.         Else
  189.           message = "Source"
  190.       End If
  191.       txtToFrom.SetFocus
  192.     ElseIf txtAmount.Text = "" Then
  193.       message = "Amount"
  194.       txtAmount.SetFocus
  195.     ElseIf txtNum.Text = "" Then
  196.       If transType = "Check" Then
  197.           message = "Check Number"
  198.         Else
  199.           message = "Deposit Number"
  200.       End If
  201.       txtNum.SetFocus
  202.   End If
  203.   If message = "" Then
  204.       'All required data fields have been filled; recording can proceed
  205.       AllDataGiven = True
  206.     Else
  207.       'Advise user of required data which is missing
  208.       MsgBox "The '" & message & "' field must be filled", , "Error"
  209.       AllDataGiven = False
  210.   End If
  211. End Function
  212. Private Sub cmdMode_Click()
  213.   'Toggle from Check to/from Deposit Slip
  214.   If transType = "Check" Then
  215.       Call SetupDeposit
  216.     Else   'transType = "Deposit"
  217.       Call SetupCheck
  218.   End If
  219.   Call InitializeFields
  220.   txtToFrom.SetFocus
  221. End Sub
  222. Private Sub cmdPrint_Click()
  223.   Dim temp As String, lineNo As Integer
  224.   Dim nameOnChk As String, balance As Single, ck As Integer, dp As Integer
  225.   Dim toFrom As String, amount As String, memo As String, theDate As String
  226.   'Print out a detailed list of all transactions.
  227.   temp = frmCheckbook.Caption             'Save the current form caption
  228.   frmCheckbook.Caption = "Printing..."    'Set form caption to indicate printing
  229.   lineNo = 1                       'Line number being printed
  230.   Open fileName For Input As #1        'Open the file
  231.   Input #1, nameOnChk, balance, ck, dp 'Read in the file header
  232.   'Print the details of the individual transactions.
  233.   Do Until EOF(1)
  234.     If lineNo >= 57 Then
  235.         '57 or more lines have been printed; start a new page
  236.         Printer.NewPage
  237.         lineNo = 1
  238.     End If
  239.     If lineNo = 1 Then
  240.         'Print the report header
  241.         Printer.Print
  242.         Printer.Print "Name: "; nameOnChk; Tab(65); FormatDateTime(Now, vbLongDate)
  243.         Printer.Print
  244.         Printer.Print , "Starting balance: "; FormatCurrency(balance)
  245.         Printer.Print
  246.         Printer.Print "Date", "Transaction"; Tab(50); "Amount";
  247.         Printer.Print Tab(65); "Balance"
  248.         Printer.Print "____", "___________"; Tab(50); "______";
  249.         Printer.Print Tab(65); "_______"
  250.         Printer.Print
  251.         Printer.Print
  252.         lineNo = 10
  253.     End If
  254.     Input #1, transType, toFrom, balance, ck, dp, amount, memo, theDate
  255.     If transType = "Check" Then
  256.         Printer.Print theDate, "Check #: "; ck; Tab(50); amount;
  257.         Printer.Print Tab(65); FormatCurrency(balance)
  258.         Printer.Print , "Payed to: "; toFrom
  259.       Else             'Transaction was a deposit
  260.         Printer.Print theDate, "Deposit #: "; dp; Tab(50); amount;
  261.         Printer.Print Tab(65); FormatCurrency(balance)
  262.         Printer.Print , "Source: "; toFrom
  263.     End If
  264.     lineNo = lineNo + 2
  265.     'If there was a memo, then print it.
  266.     If memo <> "" Then
  267.         Printer.Print , "Memo: "; memo
  268.         lineNo = lineNo + 1
  269.     End If
  270.     Printer.Print
  271.     lineNo = lineNo + 1
  272.   Loop
  273.   Close #1                    'Close the file
  274.   'Print the ending balance
  275.   Printer.Print
  276.   Printer.Print , "Ending Balance: "; FormatCurrency(balance)
  277.   Printer.EndDoc              'Send the output to the Printer
  278.   frmCheckbook.Caption = temp   'Restore the form caption
  279.   txtToFrom.SetFocus          'Set focus for the next entry
  280. End Sub
  281. Private Sub cmdQuit_Click()
  282.   ' Exit the program
  283.   End
  284. End Sub
  285. Private Sub cmdRecord_Click()
  286.   Dim amt As String, amount As Single, itemNum As Integer
  287.   'Check to ensure all required fields are filled
  288.   If AllDataGiven Then
  289.       amt = txtAmount.Text 'Amount of transaction as string
  290.       amount = Val(amt)    'Amount of transaction as number
  291.       amt = FormatCurrency(amt)
  292.       itemNum = Val(txtNum.Text)
  293.       If transType = "Check" Then
  294.           curBal = curBal - amount
  295.           lastCkNum = itemNum
  296.         Else           'TransType = "Deposit"
  297.           curBal = curBal + amount
  298.           lastDpNum = itemNum
  299.       End If
  300.       lblBalance.Caption = FormatCurrency(curBal)
  301.       Open fileName For Append As #1
  302.       Write #1, transType, txtToFrom.Text, curBal, lastCkNum, lastDpNum, amt, _
  303.                 txtMemo.Text, txtDate.Text
  304.       Close #1
  305.       Call InitializeFields
  306.       txtToFrom.SetFocus
  307.   End If
  308. End Sub
  309. Private Sub CreateDataFile()
  310.   Dim startBal As Single, ckNum As Integer
  311.   'The first time the program is run, create a data file
  312.   Open fileName For Output As #1
  313.   nameOnChk = InputBox("Name to appear on checks:")
  314.   startBal = Val(InputBox("Starting balance:"))
  315.   ckNum = Val(InputBox("Number of the first check:"))
  316.   lastCkNum = ckNum - 1   'Number of "last" check written
  317.   ckNum = Val(InputBox("Number of the first deposit slip:"))
  318.   lastDpNum = ckNum - 1   'Number of "last" deposit slip processed
  319.   curBal = startBal       'Set current balance
  320.   'First record in data file records name to appear on checks
  321.   'plus initial data for account
  322.   Write #1, nameOnChk, startBal, lastCkNum, lastDpNum
  323.   Close #1
  324. End Sub
  325. Private Sub Form_Load()
  326.   Dim today As String
  327.   'Dim drive As String
  328.   'If no data file exists, create one. Otherwise, open the
  329.   'data file and get the user's name, last used check and
  330.   'deposit slip numbers, and current balance.
  331.   'In next line adjust drive as necessary
  332.   'drive = "A:"           'Drive (or path) for data file
  333.   fileName = App.Path & "\CHKBOOK.TXT"  'Program uses one data file
  334.   If Dir(fileName) = "" Then
  335.       'Data file does not exist, so create it and obtain initial data
  336.       Call CreateDataFile
  337.     Else
  338.       Call ReadDataFile
  339.   End If
  340.   'Set name and balance labels
  341.   lblName.Caption = nameOnChk
  342.   lblBalance.Caption = FormatCurrency(curBal)
  343.   'Set the date field to the current date
  344.   today = FormatDateTime(Now, vbLongDate)
  345.   txtDate.Text = Mid(today, 2 + InStr(today, ","))
  346.   Call SetupCheck                    'Always start session with checks
  347.   Call InitializeFields
  348. End Sub
  349. Private Sub InitializeFields()
  350.   'Initialize all text entry fields except date
  351.   txtToFrom.Text = ""
  352.   txtAmount.Text = ""
  353.   txtMemo.Text = ""
  354.   If transType = "Check" Then
  355.       'Set txtNum textbox reflect next check number
  356.       txtNum.Text = Str(lastCkNum + 1)
  357.     Else               'TransType = "Deposit"
  358.       'Make txtNum textbox reflect next deposit slip number
  359.       txtNum.Text = Str(lastDpNum + 1)
  360.   End If
  361. End Sub
  362. Private Sub ReadDataFile()
  363.   Dim t As String, s As String, n As String, m As String, d As String
  364.   'Recover name to appear on checks, current balance,
  365.   'number of last check written, and number of last deposit slip processed
  366.   Open fileName For Input As #1
  367.   Input #1, nameOnChk, curBal, lastCkNum, lastDpNum
  368.   Do Until EOF(1)
  369.     'Read to the end of the file to recover the current balance and the
  370.     'last values recorded for ckNum and dpNum.
  371.     't, s, n, m and d are dummy variables and are not used at this point
  372.     Input #1, t, s, curBal, lastCkNum, lastDpNum, n, m, d
  373.   Loop
  374.   Close #1
  375. End Sub
  376. Private Sub SetupCheck()
  377.   'Prepare form for the entry of a check
  378.   transType = "Check"
  379.   frmCheckbook.Caption = "Check"
  380.   lblToFrom.Caption = "Pay To"
  381.   cmdRecord.Caption = "&Record This Check"
  382.   cmdMode.Caption = "&Switch to Deposits"
  383.   picBox.BackColor = vbCyan  'color of check is light turquoise blue
  384.   txtNum.BackColor = vbCyan
  385. End Sub
  386. Private Sub SetupDeposit()
  387.   'Prepare form for the entry of a deposit
  388.   transType = "Deposit"
  389.   frmCheckbook.Caption = "Deposit Slip"
  390.   lblToFrom.Caption = "Source"
  391.   cmdRecord.Caption = "&Record This Deposit"
  392.   cmdMode.Caption = "&Switch to Checks"
  393.   picBox.BackColor = vbYellow  'color of deposit slip is yellow
  394.   txtNum.BackColor = vbYellow
  395. End Sub
  396.